<!doctype html>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
<script src="../assert_selection.js"></script>
<script>
  test(() => {
    if (!window.testRunner) {
      assert_unreached('This test requires testRunner for copy/paste.');
      return;
    }
    assert_selection(
      [
        '<div contenteditable>',
          '<div><div>foo</div>^bar</div>baz|',
        '</div>',
        '<div contenteditable id="sample">abc</div>',
      ].join(''),
      selection => {
        selection.document.execCommand('copy');
        const sample = selection.document.getElementById('sample');
        selection.collapse(sample.firstChild, 3);
        selection.document.execCommand('paste');
      },
      [
        '<div contenteditable>',
          '<div><div>foo</div>bar</div>baz',
        '</div>',
        '<div contenteditable id="sample">abcbar<br>baz|</div>',
      ].join(''));
  }, 'Copy selection ending at end of a block');
</script>
